package com.giaothong.ui.base;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;

import com.giaothong.R;
import com.giaothong.db.SharePreferenceAdapter;
import com.giaothong.utils.ALog;

public class BaseActivity extends Activity {
	private ProgressDialog progressDialog = null;
	public SharePreferenceAdapter sharePreferenceAdapter = SharePreferenceAdapter.getInstance();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		sharePreferenceAdapter.init(this);
		progressDialog = new ProgressDialog(this);
		progressDialog.setCanceledOnTouchOutside(false);

	}

	@Override
	protected void onResume() {
		super.onResume();

		if (findViewById(R.id.btnBack) != null) {
			findViewById(R.id.btnBack).setOnClickListener(new View.OnClickListener() {

				public void onClick(View v) {
					finish();
				}
			});
		}
	}

	/**
	 * overide BackKey
	 */
	@SuppressWarnings("deprecation")
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// if key back
		ALog.d("SDK", android.os.Build.VERSION.SDK + "");
		if (Integer.parseInt(android.os.Build.VERSION.SDK) < 5 && keyCode == KeyEvent.KEYCODE_BACK) {
			onBackPressed();
			return true;
		} else {
			return super.onKeyDown(keyCode, event);
		}

	}

	@Override
	public void onBackPressed() {
		// TODO...
		super.onBackPressed();
	}

	/**
	 * show dialog
	 * 
	 * @param resMessage
	 */
	public void showDialogMessage(int resMessage) {
		progressDialog.setTitle("");
		progressDialog.setMessage(getString(resMessage));
		progressDialog.show();
	}

	/**
	 * close dialog
	 */
	public void closeDialogMessage() {
		progressDialog.dismiss();
	}

}
